Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Entity
Imports System.Linq

Public Class <OwnerU>_<TableU>DataClass

    Public Function Select_Records(ByVal <DRField> As <DRType>) As DataTable
        Using context = New <Database>DBContext()
<If Loop>
      <IsFKeyCount>
            Dim Query = (From _<OwnerU>_<TableU> In context.<OwnerU>_<TableU>
     	<ExitLoop>
</If Loop>
<If Loop>
     <IsFKeyCount>
     <And>
     <IsRelated>
     <And>
     <IsMiscTag>
                        join A<MiscTag>_<ROwner>_<RTable> in context.<ROwner>_<RTable> on _<OwnerU>_<TableU>.<Field> equals A<MiscTag>_<ROwner>_<RTable>.<RField>
     <IsFKeyCount>
     <And>
     <IsRelated>
     <And>
     <IsNotMiscTag>
                        join _<ROwner>_<RTable> in context.<ROwner>_<RTable> on _<OwnerU>_<TableU>.<Field> equals _<ROwner>_<RTable>.<RField>
</If Loop>
                        Where _<DOwner>_<DTable>.<DRField> = <DRField>                        
<If Loop>
      <IsFKeyCount>
                        Select New <OwnerU>_<TableU>Joined() With { _
     	<ExitLoop>
</If Loop>
<If Loop>
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsMiscTag>
     <And>
     <IsCurRow=[0]>
                            .<Field> = A<MiscTag>_<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsMiscTag>
     <And>
     <IsCurRow<>[0]>
                           ,.<Field> = A<MiscTag>_<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsNotMiscTag>
     <And>
     <IsCurRow=[0]>
                            .<Field> = _<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsNotMiscTag>
     <And>
     <IsCurRow<>[0]>
                           ,.<Field> = _<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsNotComboBox (Db)>
     <And>
     <IsCurRow=[0]>
                            .<Field> = _<OwnerU>_<TableU>.<Field> _
     <IsFKeyCount>
     <And>
     <IsNotComboBox (Db)>
     <And>
     <IsCurRow<>[0]>
                           ,.<Field> = _<OwnerU>_<TableU>.<Field> _
</If Loop>
<If Loop>
      <IsFKeyCount>
                        }).AsQueryable()

            Return Query.ToList().ToDataTable()
     	<ExitLoop>
</If Loop>
<If Loop>
      <IsNotFKeyCount>
            Return context.<OwnerU>_<TableU>.ToList().ToDataTable()
     	<ExitLoop>
</If Loop>
        End Using
    End Function

    Public Function Search(Byval <DRField> AS <DRType>, ByVal sField As String, ByVal sCondition As String, ByVal sValue as String) As DataTable
        Using context = New <Database>DBContext()
<If Loop>
      <IsNotFKeyCount>
            Dim Query = context.<OwnerU>_<TableU>.AsQueryable()
     	<ExitLoop>
</If Loop>
<If Loop>
      <IsFKeyCount>
            Dim Query = (From _<OwnerU>_<TableU> In context.<OwnerU>_<TableU>
     	<ExitLoop>
</If Loop>
<If Loop>
     <IsFKeyCount>
     <And>
     <IsRelated>
     <And>
     <IsMiscTag>
                        join A<MiscTag>_<ROwner>_<RTable> in context.<ROwner>_<RTable> on _<OwnerU>_<TableU>.<Field> equals A<MiscTag>_<ROwner>_<RTable>.<RField>
     <IsFKeyCount>
     <And>
     <IsRelated>
     <And>
     <IsNotMiscTag>
                        join _<ROwner>_<RTable> in context.<ROwner>_<RTable> on _<OwnerU>_<TableU>.<Field> equals _<ROwner>_<RTable>.<RField>
</If Loop>
                        Where _<DOwner>_<DTable>.<DRField> = <DRField>   
<If Loop>
      <IsFKeyCount>
                        Select New <OwnerU>_<TableU>Joined() With { _
     	<ExitLoop>
</If Loop>
<If Loop>
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsMiscTag>
     <And>
     <IsCurRow=[0]>
                            .<Field> = A<MiscTag>_<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsMiscTag>
     <And>
     <IsCurRow<>[0]>
                           ,.<Field> = A<MiscTag>_<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsNotMiscTag>
     <And>
     <IsCurRow=[0]>
                            .<Field> = _<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsComboBox (Db)>
     <And>
     <IsNotMiscTag>
     <And>
     <IsCurRow<>[0]>
                           ,.<Field> = _<ROwner>_<RTable>.<RDisplayFieldU> _
     <IsFKeyCount>
     <And>
     <IsNotComboBox (Db)>
     <And>
     <IsCurRow=[0]>
                            .<Field> = _<OwnerU>_<TableU>.<Field> _
     <IsFKeyCount>
     <And>
     <IsNotComboBox (Db)>
     <And>
     <IsCurRow<>[0]>
                           ,.<Field> = _<OwnerU>_<TableU>.<Field> _
</If Loop>
<If Loop>
      <IsFKeyCount>
                        }).AsQueryable()
     	<ExitLoop>
</If Loop>
        Try
                If sValue IsNot Nothing Then
                    If sCondition = "Contains" Then
                        Query = Query.Where(Function(p) _ 
    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().Contains(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().Contains(sValue.Trim().ToLower())) _
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().Contains(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.Value.ToString().Contains(sValue)) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().Contains(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().Contains(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().Contains(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.Value.ToString().Contains(sValue)) _ 
    </If Loop>
                                         )
                    ElseIf sCondition = "Starts with..." Then
                        Query = Query.Where(Function(p) _ 
    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().StartsWith(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().StartsWith(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().StartsWith(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow=[0]>
                                                 ("<FieldC>".ToString().Equals(sField) And p.<Field>.Value.ToString().StartsWith(sValue)) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().StartsWith(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().StartsWith(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.ToString().Trim().ToLower().StartsWith(sValue.Trim().ToLower())) _ 
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                                                 Or ("<FieldC>".ToString().Equals(sField) And p.<Field>.Value.ToString().StartsWith(sValue)) _ 
    </If Loop>
                                         )
                    ElseIf sCondition = "Equals" Then
    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsNotComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> = m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value = m<Field>)
    </If Loop>
                        End If
                    ElseIf sCondition = "More than..." Then
    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsNotComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> > m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value > m<Field>)
    </If Loop>
                        End If
                    ElseIf sCondition = "Less than..." Then
    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsNotComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> < m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value < m<Field>)
    </If Loop>
                        End If
                    ElseIf sCondition = "Equal or more than..." Then
    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsNotComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> >= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value >= m<Field>)
    </If Loop>
                        End If
                    ElseIf sCondition = "Equal or less than..." Then
    <If Loop>
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow=[0]>
                        If "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
        <IsNotNull>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNotNullable>
   	<And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsNotComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field> <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsRDisplayField>
        <And>
        <IsComboBox (Db)>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = sValue
                            Query = Query.Where(Function(p) p.<Field> <= m<Field>)
   	<IsNotText>
   	<And>
   	<IsNotNText>
   	<And>
   	<IsNull>
   	<And>
   	<IsNullable>
   	<And>
        <IsNotRDisplayField>
        <And>
   	<IsCurRow<>[0]>
                        ElseIf "<FieldC>".Equals(sField) Then
                            Dim m<Field> = <Convert>(sValue)
                            Query = Query.Where(Function(p) p.<Field>.Value <= m<Field>)
    </If Loop>
                        End If
                End If
            End If
        Catch ex As Exception
        End Try
            Return Query.ToList().ToDataTable()
        End Using
    End Function

    Public Function Select_Record(_<OwnerU>_<TableU> As <OwnerU>_<TableU>) As <OwnerU>_<TableU>
        Using context = New <Database>DBContext()
            Return context.<OwnerU>_<TableU>.Find(
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                        _<OwnerU>_<TableU>.<FieldU> _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                        , _<OwnerU>_<TableU>.<FieldU> _
    </If Loop>
                                        )
        End Using
    End Function

    Public Function Add(_<OwnerU>_<TableU> As <OwnerU>_<TableU>) As Boolean
        Using context = New <Database>DBContext()
            context.<OwnerU>_<TableU>.Add(_<OwnerU>_<TableU>)
            Return context.SaveChanges() > 0
        End Using
    End Function

    Public Function Update(_<OwnerU>_<TableU> As <OwnerU>_<TableU>) As Boolean
        Using context = New <Database>DBContext()
            context.<OwnerU>_<TableU>.Attach(_<OwnerU>_<TableU>)
            context.Entry(_<OwnerU>_<TableU>).State = System.Data.Entity.EntityState.Modified
            Return context.SaveChanges() > 0
        End Using
    End Function

    Public Function Delete(_<OwnerU>_<TableU> As <OwnerU>_<TableU>) As Boolean
        Using context = New <Database>DBContext()
            context.<OwnerU>_<TableU>.Remove(context.<OwnerU>_<TableU>.Find(
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                        _<OwnerU>_<TableU>.<FieldU> _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                        , _<OwnerU>_<TableU>.<FieldU> _
    </If Loop>
                                        ))
            Return context.SaveChanges() > 0
        End Using
    End Function

    Public Function Delete(ByVal <DRField> As <DRType>) As Boolean
        Try
            Using context = New <Database>DBContext()
                Dim Query = (From _<OwnerU>_<TableU> In context.<OwnerU>_<TableU> Where _<OwnerU>_<TableU>.<DRField> = <DRField>).AsQueryable()
                Dim _<OwnerU>_<TableU>_ As <OwnerU>_<TableU> = Query.First()
                context.<OwnerU>_<TableU>.Remove(_<OwnerU>_<TableU>_)
                Return context.SaveChanges() > 0
            End Using
        Catch
        End Try
        Return True
    End Function

End Class
